home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Expander / Sample Source / x_CApp.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  6.0 KB  |  248 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  x_CApp.cp
  3.  
  4.                 CApp "Lower-Layer" Application Class
  5.     
  6.     Copyright Â© 1994 My Software Inc. All rights reserved.
  7.  
  8.     Generated by Visual Architectâ„¢ 9:40 PM Wed, Jun 8, 1994
  9.  
  10.     This file is rewritten each time you generate code. You should not
  11.     make changes to this file; changes should go in the CApp.cp
  12.     file, instead.
  13.  
  14.     If you want to change how Visual Architect generates this file, you can
  15.     change the template for this file. It is "_App_cp" in the Visual Architect
  16.     Templates folder.
  17.  
  18.  ******************************************************************************/
  19.  
  20. #include "x_CApp.h"
  21.  
  22. #include "CApp.h"
  23.  
  24. #include "References.h"
  25. #include "CMain.h"
  26. #include <CBartender.h>
  27. #include <Commands.h>
  28. #include <CDesktop.h>
  29. #include <CFile.h>
  30. #include <CFWDesktop.h>
  31. #include <CList.h>
  32. #include <Packages.h>
  33. #include <TBUtilities.h>
  34. #include <TCLForceReferences.h>
  35.  
  36. #include "CDisplayPane.h"
  37. #include "CMain.h"
  38.  
  39. extern OSType        gSignature;            /* Creator for Application's files    */
  40. extern CBartender    *gBartender;        /* Manages all menus                */
  41. extern CDesktop        *gDesktop;            /* The visible Desktop                */
  42.  
  43. #define ALRTabout 500
  44.  
  45.  
  46. TCL_DEFINE_CLASS_M1(x_CApp, CApplication);
  47.  
  48. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  49.  
  50.  
  51. /******************************************************************************
  52.  Ix_CApp
  53.  
  54.         Initialize an Application.
  55.  ******************************************************************************/
  56.  
  57. void    x_CApp::Ix_CApp(short extraMasters, Size aRainyDayFund,
  58.                                     Size aCriticalBalance, Size aToolboxBalance)
  59.  
  60. {
  61.     IApplication(extraMasters, aRainyDayFund, aCriticalBalance, aToolboxBalance);
  62. }
  63.  
  64.  
  65. /******************************************************************************
  66.  SetUpFileParameters    {OVERRIDE}
  67.  
  68.     Specify the kinds of files your application opens
  69.  ******************************************************************************/
  70.  
  71. void x_CApp::SetUpFileParameters()
  72. {
  73.     CApplication::SetUpFileParameters();
  74.  
  75.         // File types as defined in CApp.h
  76.  
  77.     sfNumTypes = kNumFileTypes;
  78.     sfFileTypes[0] = kFileType1;
  79.     sfFileTypes[1] = kFileType2;
  80.     sfFileTypes[2] = kFileType3;
  81.     sfFileTypes[3] = kFileType4;
  82.     gSignature = 'cApp';
  83. }
  84.  
  85.  
  86. /******************************************************************************
  87.  SetUpMenus {OVERRIDE}
  88.  
  89.         Set up the menus after first creating any floating/tearoff
  90.         windows. The latter must be done before the bartender inits.
  91.  ******************************************************************************/
  92.  
  93. void x_CApp::SetUpMenus()
  94. {
  95.  
  96.     CApplication::SetUpMenus();
  97. }
  98.  
  99.  
  100. /******************************************************************************
  101.  ForceClassReferences    {OVERRIDE}
  102.  
  103.     Reference classes that might do object I/O.
  104.  ******************************************************************************/
  105.  
  106. void x_CApp::ForceClassReferences(void)
  107.  
  108. {
  109.     CApplication::ForceClassReferences();
  110.  
  111.                                             /* From References.c            */
  112.     ReferenceStdClasses();                    /*     See template file Ref        */
  113.     
  114.     TCL_FORCE_REFERENCE(CDisplayPane);
  115. }
  116.  
  117.  
  118. /**** C O M M A N D   M E T H O D S ****/
  119.  
  120.  
  121. /******************************************************************************
  122.  DoCommand    {OVERRIDE}
  123.  
  124.     Handle application commands
  125.  ******************************************************************************/
  126.  
  127. void x_CApp::DoCommand(long theCommand)
  128.  
  129. {
  130.     switch (theCommand)
  131.     {
  132.         case cmdAbout:
  133.  
  134.                 // Simple About alert. Subclasses will probably
  135.                 // trap this command to do something sexier.
  136.  
  137.             PositionDialog('ALRT', ALRTabout);
  138.             InitCursor();
  139.             ParamText("\pCApp", "\pMy Software Inc", "\p", "\p");
  140.             Alert(ALRTabout, NULL);
  141.             break;
  142.  
  143.         default:
  144.             CApplication::DoCommand(theCommand);
  145.             break;
  146.     }
  147. }
  148.  
  149.  
  150. /**** D O C U M E N T   M E T H O D S ****/
  151.  
  152.  
  153. /******************************************************************************
  154.  CreateDocument    {OVERRIDE}
  155.  
  156.     Make a new document when user chooses New from file menu.
  157.     This method is entirely generic except for the document class.
  158.  ******************************************************************************/
  159.  
  160. void x_CApp::CreateDocument()
  161.  
  162. {
  163.     CDocument    *volatile theDocument = NULL;
  164.  
  165.     theDocument = TCL_NEW(CMain,());
  166.     TRY
  167.     {
  168.         ((CMain*) theDocument)->ICMain();
  169.         theDocument->NewFile();
  170.     }
  171.     CATCH
  172.     {
  173.         ForgetObject(theDocument);
  174.     }
  175.     ENDTRY
  176. }
  177.  
  178.  
  179. /******************************************************************************
  180.  OpenDocument    {OVERRIDE}
  181.  
  182.     Open a document when user chooses Open from file menu.
  183.     For multiple document types, this method assumes that each
  184.     document is associated with a single file type. 
  185.  ******************************************************************************/
  186.  
  187. void x_CApp::OpenDocument(SFReply *macSFReply)
  188.  
  189. {
  190.     CDocument    *volatile theDocument = NULL;
  191.  
  192.     theDocument = TCL_NEW(CMain,());
  193.     TRY
  194.     {
  195.         ((CMain*) theDocument)->ICMain();
  196.         theDocument->OpenFile(macSFReply);
  197.     }
  198.     CATCH
  199.     {
  200.         ForgetObject(theDocument);
  201.     }
  202.     ENDTRY
  203. }
  204.  
  205.  
  206.  
  207.  
  208. /******************************************************************************
  209.  FileAlreadyOpen
  210.  
  211.     If file already in use return TRUE and bring owning document's
  212.     window to the foreground.  Sent from document before opening.
  213.  ******************************************************************************/
  214.  
  215.     static Boolean EqualFile(CDirector *obj, long param)
  216.     {
  217.         FSSpec        theFileSpec;
  218.         CFile        *theFile;
  219.         FSSpec        *theParam = (FSSpec*) param;
  220.  
  221.         if (member(obj, CDocument))
  222.         {
  223.             theFile = ((CDocument*)obj)->itsFile;
  224.             if (theFile == NULL)
  225.                 return FALSE;
  226.             theFile->GetFSSpec(&theFileSpec);
  227.             return theFileSpec.vRefNum == theParam->vRefNum
  228.                 && theFileSpec.parID == theParam->parID
  229.                 && !IUEqualString(theFileSpec.name, theParam->name);
  230.         }
  231.         return FALSE;
  232.     }
  233.  
  234. Boolean x_CApp::FileAlreadyOpen(
  235.     CFile        *aFile)
  236.  
  237. {
  238.     FSSpec        fileSpec;
  239.     CDirector    *theDirector = NULL;
  240.  
  241.     aFile->GetFSSpec(&fileSpec);
  242.     if (itsDirectors)                        /* Search for matching file        */
  243.         theDirector = (CDirector*) itsDirectors->FindItem1(EqualFile, (long) &fileSpec);
  244.     if (theDirector)                        /* If find one, bring to front    */
  245.         theDirector->GetWindow()->Select();
  246.     return theDirector != NULL;                /* Tell caller                    */
  247. }
  248.